﻿using MapsterMapper;
using TokenApi.Service.DataAccess;
using TokenApi.Service.Infrastructure;

namespace TokenApi.Service.Service;

public abstract class ApplicationService(IServiceProvider serviceProvider)
{
    protected T GetService<T>()
    {
        return serviceProvider.GetRequiredService<T>();
    }

    protected T? GetKeyedService<T>(string key)
    {
        return serviceProvider.GetKeyedService<T>(key);
    }

    protected T GetRequiredKeyedService<T>(string key)
        => serviceProvider.GetRequiredKeyedService<T>(key);

    protected IUserContext UserContext => GetService<IUserContext>();

    protected TokenApiDbContext DbContext => GetService<TokenApiDbContext>();

    protected IMapper Mapper => GetService<IMapper>();
}